package com.tuotu.gps.view;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.tuotu.gps.R;


/**
 * Created by XuYeWen on 2018/1/18.
 */

public class FreeDialog extends AlertDialog implements MyDialogInterface {

    private TextView tvMsg;
    private TextView tvTitle;
    private Button bt1;
    private Button bt2;
    private Button bt3;
    private TextView bt3Divider;

    MyDialogInterface.OnClickListener bt1OnClickListener;
    MyDialogInterface.OnClickListener bt2OnClickListener;
    MyDialogInterface.OnClickListener bt3OnClickListener;

    public FreeDialog(Context context) {
        super(context,R.style.recordMotionDialogStyle);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
        tvMsg = view.findViewById(R.id.tvMsg);
        tvTitle = view.findViewById(R.id.tvTitle);
        bt1 = view.findViewById(R.id.bt1);
        bt2 = view.findViewById(R.id.bt2);
        bt3 = view.findViewById(R.id.bt3);
        bt3Divider = view.findViewById(R.id.bt3Divider);

        setView(view);

        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=bt1OnClickListener)
                    bt1OnClickListener.onClick(FreeDialog.this,1);
            }
        });
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=bt2OnClickListener)
                    bt2OnClickListener.onClick(FreeDialog.this,2);
            }
        });
        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=bt3OnClickListener)
                    bt3OnClickListener.onClick(FreeDialog.this,3);
            }
        });
    }

    public void setBt1Click(CharSequence text, MyDialogInterface.OnClickListener onClickListener) {
        bt1.setText(text);
        bt1OnClickListener=onClickListener;
    }

    public void setBt2Click(CharSequence text, MyDialogInterface.OnClickListener onClickListener) {
        bt2.setVisibility(View.VISIBLE);
        bt2.setText(text);
        bt2OnClickListener=onClickListener;
    }
    public void setBt3Click(CharSequence text, MyDialogInterface.OnClickListener onClickListener) {
        bt3.setVisibility(View.VISIBLE);
        bt3Divider.setVisibility(View.VISIBLE);
        bt3.setText(text);
        bt3OnClickListener=onClickListener;
    }

    public void setTvMsg(CharSequence text) {
        tvMsg.setVisibility(View.VISIBLE);
        tvMsg.setText(text);
    }
    public void setTvTitle(CharSequence text) {
        tvTitle.setVisibility(View.VISIBLE);
        tvTitle.setText(text);
    }

    @Override
    public void onCancel() {
        cancel();
    }

    @Override
    public void onDismiss() {
        dismiss();
    }
}
